function loss = RPfigures_c(pars)
%Compute loss function from IRF matching exercise

global T t_irf g_irf t_sd g_sd
%Read policy parameters
rho = pars(1);
gammaG = pars(2); gammaT = pars(3); lambdaG = pars(4); lambdaT = pars(5);

%Solve for policy functions for k and c
[eta H Ac Bc] = RPfigures_a(pars);
%Solve for policy functions for g and t
Ag = gammaG*Ac;
Bg = gammaG*Bc + (1+lambdaG);
At = (gammaT + lambdaT*gammaG)*Ac;
Bt = (gammaT + lambdaT*gammaG)*Bc + lambdaT*(1+lambdaG);
%Solve for ARMA for g and t
mug = Bg; nug = Ag*H - Bg*eta;
mut = Bt; nut = At*H - Bt*eta;
%Compute IRF for T periods
irfg = RPfigures_b([eta rho mug nug],T);
irft = RPfigures_b([eta rho mut nut],T);
%Compute loss function
loss = sum(((t_irf - irft).^2)) + sum(((g_irf - irfg).^2));